package io;

import java.io.*;
import java.nio.Buffer;

/**
 * 使用缓冲流完成文件的复制操作
 *
 * 缓冲流：
 * java.io.BufferedInputStream和BufferedOutputStream
 * 缓冲流是一对高级流，在流连接中的作用是提高读写字节数据的效率
 */
public class CopyDemo3 {
    public static void main(String[] args) throws IOException {
        FileInputStream fis = new FileInputStream("note.txt");
        BufferedInputStream bis = new BufferedInputStream(fis);
        FileOutputStream fos = new FileOutputStream("note.or.txt");
        BufferedOutputStream bos = new BufferedOutputStream(fos);
        int d;

        long start = System.currentTimeMillis();
        while((d=bis.read())!=-1){
            bos.write(d);
        }
        long end = System.currentTimeMillis();
        System.out.println("复制完毕！耗时："+(end-start)+"ms");
        bos.close();
        bis.close();
    }
}
